#!/usr/bin/perl
#index.cgi

require './shareman-lib.pl';

&ReadParse();

&header($text{'shares_title'}, "", "index", 0, 1);
#print "<hr>\n";
#print "<b><p>", $text{'share_folders'}, "</p></b>\n";
#&write_user_conf(cm1);
print "<form name=editform action=edit_share.cgi method=post onsubmit='disable_buttons();'>\n";
my $nd = &list_shares();

print <<EOF;
<script>
function GetSelectedShare(obj, n)
{
	var i;
	found = false;
	if (n >1)
	for(i = 0; i < document.editform.sharedir.length; i++)
	{
		if (document.editform.sharedir[i].checked)
		{
			found = true;
			break;
		}
	}
	else if (n == 1)
	{
		if (document.editform.sharedir.checked)
			{
				found = true;
			}
	}

	if (found)
	{
		if (n > 1)
			document.editform.sharepath.value = document.editform.sharedir[i].value;
		else
			document.editform.sharepath.value = document.editform.sharedir.value;
	}
	else
		document.editform.sharepath.value = '';
	if (obj == document.editform.newshare)
		found = true;
	return found;
}

function SetEditValue(obj, n)
{
	if (GetSelectedShare(obj, n))
	{
		if (obj ==document.editform.delshare)
		{
			if (!confirm("$text{'delete_share_query'}"))
				return false;
		}
	}
	else
	{
		alert("$text{'noselectshare'}");
		return false;
	}
	if (obj == document.editform.newshare)
		document.editform.edit.value = 'create'
	else if (obj == document.editform.editshare)
		document.editform.edit.value = 'property'
	else
		document.editform.edit.value = 'delete';
	return true;
}

function disable_buttons()
{
	document.forms[0].newshare.disabled = true;
	document.forms[0].delshare.disabled = true;
	document.forms[0].editshare.disabled = true;
}
</script>
EOF


print "<input type=hidden name=edit>\n";
print "<input type=hidden name=sharepath>\n";
print "<input type=hidden name=src value='disk'>\n";
#print "<table class=mode1 border=0 cellspacing=0 cellpadding=1 width=75%><tr>\n";
#print "<td><input type=submit name=newshare value=\"$text{'create_share'}\" onclick='return SetEditValue(this, $nd)' class=button></td>\n";

#if ($nd)
#{
#	print "<td align=center><input type=submit name=delshare value=\"$text{'delete_share'}\" onclick='return SetEditValue(this, $nd)' class=button></td>\n";
#	print "<td align=right><input type=submit name=editshare value=\"$text{'edit_share'}\" onclick='return SetEditValue(this, $nd)' class=button></td>\n";
#}
#print "</tr></table>\n";
print "</form>\n";
#print "</p>\n";

#print "<p></p><i>", $text{'sharetypes_hint'}, "</i>";
#print "<hr>\n";
&footer("/", $text{'index'});
